import {defineStore} from "pinia";
//引入获取验证码的请求方法
import {getCaptcha} from "@/api/login";

export interface User {
    userId: number,
    userType: string,
    userPoint: number,
    userCompany: string,
    userPosition: string,
    userDepartment: string,
    userAddress: string,
    userIdentifyTag: string,
    userNickName: string,
}

export const useLoginStore = defineStore('Login', {
    actions: {
        exit() {
            this.setup = false;
        },
        login() {
            this.show = true;
        },
        //获取验证码的方法
        async getCode(phoneNumber: string) {
            //在向服务器携带手机号码，获取验证码
            await getCaptcha(phoneNumber);

        }
    },
    state() {
        return {
            show: false,
            setup: true,//setup用于控制登录组件的dialog显示与隐藏
            admin: false,
            code: '',
            token: "",
            userinfo: {
                userId: 0,
                userType: "",
                userPoint: 0,
                userCompany: "",
                userPosition: "",
                userDepartment: "",
                userAddress: "",
                userIdentifyTag: "",
                userNickName: "",
            } as User
        }
    }
})